package util

import (
	"encoding/json"
	logger "gitee.com/zaper/private-logger"
	"github.com/gin-gonic/gin"
)

type HttpContext struct{}

func HttpContextJSON(c *gin.Context, response any) {
	c.JSON(200, response)
}

type HttpResponseError struct {
	ErrorCode int32  `json:"error_code"`
	ErrorMess string `json:"error_mess"`
}

func NewHttpResponseError(errorCode int32, errorMess string) *HttpResponseError {
	return &HttpResponseError{
		ErrorCode: errorCode,
		ErrorMess: errorMess,
	}
}

func (httpResponseError *HttpResponseError) ToJsonString() string {
	resp, err := json.Marshal(httpResponseError)
	if err != nil {
		logger.Infof("To json fail , Marshal fail , error is %s", err)
		return ""
	}
	return string(resp)
}
